#include<iostream>
#include<map>
#include<vector>
#include<stack>
#include<functional>
#include<algorithm>
#include<string>
using namespace std;

class Solution
{
public:

    void TrunSuffix(string& s, size_t& i, vector<string>& ret)
    {
        stack<char> st;
        map<char, int> mp{ {'+',1},{'-',1} ,{'*',2} ,{'/',2} };

        while (i < s.size())
        {
            if (isdigit(s[i]))
            {
                string num;
                for (; i < s.size(); i++)
                {
                    if (isdigit(s[i]))
                    {
                        num += s[i];
                    }
                    else
                    {
                        break;
                    }
                }
                ret.push_back(num);
            }
            else if (s[i] == '(')
            {
                TrunSuffix(s, ++i, ret);
            }
            else if (s[i] == ')')
            {
                ++i;
                while (!st.empty())
                {
                    char ch = st.top();
                    st.pop();
                    ret.push_back(string(1, ch));
                }
                return;
            }
            else
            {
                if (st.empty() || mp[st.top()] < mp[s[i]])
                {
                    st.push(s[i++]);
                }
                else
                {
                    char ch = st.top();
                    st.pop();
                    ret.push_back(string(1, ch));
                    st.push(s[i++]);
                }
            }
        }

        while (!st.empty())
        {
            char ch = st.top();
            st.pop();
            ret.push_back(string(1, ch));
        }
    }

    int Suffix(vector<string>& ret)
    {
        map<string, function<int(int, int)>>mp =
        {
            {"+", [](int a, int b) {return a + b; }},
            { "-", [](int a, int b) {return a - b; } },
            { "*", [](int a, int b) {return a * b; } },
            {"/", [](int a, int b) {return a / b; }}
        };

        stack<int> st;

        for (auto& e : ret)
        {
            if (mp.count(e))
            {
                int right = st.top();
                st.pop();
                int left = st.top();
                st.pop();
                int r = mp[e](left, right);
                st.push(r);
            }
            else
            {
                st.push(stoi(e));
            }
        }
        return st.top();
    }

    int calculate(string s)
    {
        //1+2-(3*4)
        string news;
        for (size_t j = 0; j < s.size(); j++)
        {
            if (s[j] != ' ')
            {
                news += s[j];
            }
        }

        s.swap(news);
        news = "";

        for (size_t j = 0; j < s.size(); j++)
        {

            if (s[j] == '-' && (j == 0 || (!isdigit(s[j - 1]) && s[j - 1] != ')')))
            {
                news += "0-";
            }
            else
            {
                news += s[j];
            }
        }
        s.swap(news);
        news = "";

        int flag = 0;
        for (int i = 0; i < s.size(); i++)
        {
            if (s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/')
                flag = 1;
        }

        if (!flag)
        {
            string news;
            for (auto& e : s)
            {
                if (isdigit(e))
                {
                    news += e;
                }

            }
            return stoi(news);
        }

        vector<string> ret;
        size_t i = 0;
        TrunSuffix(s, i, ret);
        return Suffix(ret);
    }
};




int main()
{

    int n=  Solution().calculate(  "(1+(4+5+2)-3)+(6+8)"   );
    cout << n << endl;



	return 0;
}